const mongoose = require("mongoose")
const bcryptjs = require('bcryptjs');
let admModel = mongoose.model("admModel")

// 获取管理员
module.exports.getAdm = async function ({pageSize, currentPage}){
    const total = (await admModel.find()).length;
    // rows 获取的是分页的管理员数据
    const rows = await admModel
        .find()
        .limit(pageSize - 0)   // limit(number) 用于设置请求数据的条数
        .skip((currentPage - 1) * pageSize);   // 用于设置跳过多少条数据
    return { total, rows }
}
module.exports.addAdm = async function (user) {
    return await admModel.create(user);
}
//updateAdm 修改管理员
module.exports.updateAdm = async function ({_id,username,password}) {
    return await admModel.updateOne({ _id }, {username,password});
}
//deleteAdm 删除管理员
module.exports.deleteAdm = async function (row) {
    return await admModel.deleteOne(row);
}

//登录
module.exports.login = async function (user){
    const data = await admModel.find(user)
    console.log(data)
    return data
}